<template>
  <div class="app-container">
    <el-form :model="searchForm" label-width="100px" @keyup.enter.native="search()">
      <el-row>
        <el-col class="other">
          <el-form-item label="分类" size="small">
            <el-select v-model="searchForm.classification" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.classificationList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="类型" size="small">
            <el-select v-model="searchForm.genre" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.genreList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="一级部门" size="small">
            <el-select v-model="searchForm.primarySector" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.primarySectorList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="二级部门" size="small">
            <el-select v-model="searchForm.secondarySector" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.secondarySectorList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item prop="tertiarySector" label="三级部门" size="small">
            <el-input v-model="searchForm.tertiarySector"></el-input>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="员工姓名" size="small">
            <el-input v-model="searchForm.name"></el-input>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="用工形式" size="small">
            <el-select v-model="searchForm.form" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.formList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="性别" size="small">
            <el-select v-model="searchForm.sex" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option value='1' label="男"></el-option>
              <el-option value='0' label="女"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="出生月份" size="small">
            <el-select v-model="searchForm.birthdayMonth" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.birthdayMonthList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col class="ageOther">
          <el-form-item label="年龄" size="small">
            <el-col class="searchBtn">
              <el-input type="number" v-model.number="searchForm.startEmployeeAge">
                <span slot="suffix">岁</span>
              </el-input>
            </el-col>
            <el-col style="text-align: center;width: 50px">
              至
            </el-col>
            <el-col class="searchBtn">
              <el-input type="number" v-model.number="searchForm.endEmployeeAge">
                <span slot="suffix">岁</span>
              </el-input>
            </el-col>
          </el-form-item>
        </el-col>
        <el-col class="ageOther">
          <el-form-item label="司龄" size="small">
            <el-col class="searchBtn">
              <el-input type="number" v-model.number="searchForm.startAge">
                <span slot="suffix">年</span>
              </el-input>
            </el-col>
            <el-col style="text-align: center;width: 50px">
              至
            </el-col>
            <el-col class="searchBtn">
              <el-input type="number" v-model.number="searchForm.endAge">
                <span slot="suffix">年</span>
              </el-input>
            </el-col>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="文化程度" size="small">
            <el-select v-model="searchForm.education" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.educationList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="ageOther">
          <el-form-item label="工作年限" size="small">
            <el-col class="searchBtn">
              <el-input type="number" v-model.number="searchForm.startWorkYear">
                <span slot="suffix">年</span>
              </el-input>
            </el-col>
            <el-col style="text-align: center;width: 50px">
              至
            </el-col>
            <el-col class="searchBtn">
              <el-input type="number" v-model.number="searchForm.endWorkYear">
                <span slot="suffix">年</span>
              </el-input>
            </el-col>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="婚姻状况" size="small">
            <el-select v-model="searchForm.marriage" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.marriageList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="政治面貌" size="small">
            <el-select v-model="searchForm.political" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.politicalList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="职称" size="small">
            <el-select v-model="searchForm.jobTitle" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.jobTitleList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="执业注册" size="small">
            <el-input v-model="searchForm.professionalRegistered"></el-input>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="档案存放地" size="small">
            <el-select v-model="searchForm.archivesAddress" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.archivesAddressList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="other">
          <el-form-item label="员工状态" size="small">
            <el-select v-model="searchForm.isDimission" placeholder="请选择">
              <el-option value="" label="全部"></el-option>
              <el-option
                v-for="item in global.isDimissionList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="searchBtn">
          <el-form-item size="small">
            <el-button type="primary" icon="el-icon-search" @click="search()">搜索</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="table-btn">
      <!--<el-button type="primary" size="small" icon="el-icon-plus" v-if="roleType!==6" @click="addTeam()">添加</el-button>-->
      <!--<el-button type="primary" size="small" icon="el-icon-download" @click="downloadFile">导入</el-button>-->
      <!--<input class="file" type="file" @change="fileChanged" ref="file"/>-->
      <a target="_blank"
         :href="`/employeeExcel/export?${encodeURI(exportUrl)}`" v-if="roleType!==6">
        <el-button type="warning" size="small" icon="el-icon-upload2">
          导出
        </el-button>
      </a>
      <el-dialog :title="dialogTitle" :visible.sync="outerVisible" width="1000px">
        <el-form ref="teamRow" :rules="rules" :model="teamRow" label-width="120px">
          <el-collapse v-model="teamRowCollapse" accordion>
            <el-collapse-item title="个人基本信息" name="1">
              <el-row>
                <el-col class="other">
                  <el-form-item label="分类" size="small">
                    <el-select v-model="teamRow.classification" placeholder="请选择">
                      <el-option
                        v-for="item in global.classificationList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="二级部门" size="small">
                    <el-select v-model="teamRow.secondarySector" placeholder="请选择">
                      <el-option
                        v-for="item in global.secondarySectorList"
                        :key="item.label"
                        :label="item.value"
                        :value="item.label">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="所属团队" size="small">
                    <!--<el-autocomplete-->
                    <!--v-model="teamRow.teamName"-->
                    <!--:fetch-suggestions="querySearchTeam"-->
                    <!--@select="handleSelectTeam"-->
                    <!--placeholder="请输入内容"-->
                    <!--&gt;-->
                    <!--</el-autocomplete>-->
                    <el-input type="text" v-model="teamRow.teamName" disabled></el-input>
                  </el-form-item>
                  <el-form-item label="职级" size="small">
                    <el-select v-model="teamRow.rank" placeholder="请选择">
                      <el-option
                        v-for="item in global.rankList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item prop="sex" label="性别" size="small">
                    <el-radio-group v-model="teamRow.sex">
                      <el-radio :label="1">男</el-radio>
                      <el-radio :label="0">女</el-radio>
                    </el-radio-group>
                  </el-form-item>
                  <el-form-item label="出生日期" size="small">
                    <el-date-picker
                      v-model="teamRow.birthday"
                      type="date"
                      value-format="timestamp"
                      placeholder="选择日期"
                      style="width: 190px">
                    </el-date-picker>
                  </el-form-item>
                  <el-form-item label="司龄" size="small">
                    {{ Math.floor((new Date().getTime() - teamRow.hireDate)/1000/60/60/(24*30*12))||0}}年{{
                    Math.floor((Math.floor((new Date().getTime() - teamRow.hireDate)/1000/60/60%(24*30*12))) /
                    (24 * 30 ))||0}}月
                  </el-form-item>
                </el-col>
                <el-col class="other">
                  <el-form-item label="类型" size="small">
                    <el-select v-model="teamRow.genre" placeholder="请选择">
                      <el-option
                        v-for="item in global.genreList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="员工编号" size="small">
                    <el-input v-model="teamRow.employeeCode"></el-input>
                  </el-form-item>
                  <el-form-item label="被挂靠人" size="small">
                    <el-input v-model="teamRow.affiliatedPerson"></el-input>
                  </el-form-item>
                  <el-form-item prop="name" label="姓名" size="small">
                    <el-input v-model="teamRow.name"></el-input>
                  </el-form-item>
                  <el-form-item label="用工形式" size="small">
                    <el-select v-model="teamRow.form" placeholder="请选择">
                      <el-option
                        v-for="item in global.formList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="年龄" size="small">
                    {{ Math.floor((new Date().getTime() - teamRow.birthday)/1000/60/60/(24*30*12))||0}}岁
                  </el-form-item>
                </el-col>
                <el-col class="other">
                  <el-form-item label="一级部门" size="small">
                    <el-select v-model="teamRow.primarySector" placeholder="请选择">
                      <el-option
                        v-for="item in global.primarySectorList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item prop="tertiarySector" label="三级部门" size="small">
                    <el-autocomplete
                      v-model="teamRow.tertiarySector"
                      :fetch-suggestions="querySearchTertiarySector"
                      placeholder="请输入内容"
                    >
                    </el-autocomplete>
                  </el-form-item>
                  <el-form-item label="职务" size="small">
                    <el-input v-model="teamRow.position"></el-input>
                  </el-form-item>
                  <el-form-item prop="idNumber" label="身份证" size="small">
                    <el-input v-model="teamRow.idNumber"></el-input>
                  </el-form-item>
                  <el-form-item label="联系电话" size="small">
                    <el-input v-model="teamRow.tel"></el-input>
                  </el-form-item>
                  <el-form-item label="入职日期" size="small">
                    <el-date-picker
                      v-model="teamRow.hireDate"
                      type="date"
                      value-format="timestamp"
                      placeholder="选择日期"
                      style="width: 190px">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-collapse-item>
            <el-collapse-item title="个人其他信息" name="2">
              <el-row>
                <el-col class="other">
                  <el-form-item label="邮箱" size="small">
                    <el-input v-model="teamRow.email"></el-input>
                  </el-form-item>
                  <el-form-item label="专业" size="small">
                    <el-input v-model="teamRow.professional"></el-input>
                  </el-form-item>
                  <el-form-item label="婚姻状况" size="small">
                    <el-select v-model="teamRow.marriage" placeholder="请选择">
                      <el-option
                        v-for="item in global.marriageList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="紧急联系人" size="small">
                    <el-input v-model="teamRow.urgentPeople"></el-input>
                  </el-form-item>
                </el-col>
                <el-col class="other">
                  <el-form-item label="文化程度" size="small">
                    <el-select v-model="teamRow.education" placeholder="请选择">
                      <el-option
                        v-for="item in global.educationList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="毕业时间" size="small">
                    <el-date-picker
                      v-model="teamRow.graduationTime"
                      type="date"
                      value-format="timestamp"
                      placeholder="选择日期"
                      style="width: 190px">
                    </el-date-picker>
                  </el-form-item>
                  <el-form-item label="政治面貌" size="small">
                    <el-select v-model="teamRow.political" placeholder="请选择">
                      <el-option
                        v-for="item in global.politicalList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="紧急联系电话" prop="homePhone" size="small">
                    <el-input v-model="teamRow.homePhone"></el-input>
                  </el-form-item>
                </el-col>
                <el-col class="other">
                  <el-form-item label="毕业学校" size="small">
                    <el-input v-model="teamRow.graduationSchool"></el-input>
                  </el-form-item>
                  <el-form-item label="工作年限" size="small">
                    {{ Math.floor((new Date().getTime() - teamRow.graduationTime)/1000/60/60/(24*30*12))||0}}年{{
                    Math.floor((Math.floor((new Date().getTime() - teamRow.graduationTime)/1000/60/60%(24*30*12))) /
                    (24 * 30 ))||0}}月
                  </el-form-item>
                  <el-form-item label="籍贯" size="small">
                    <el-input v-model="teamRow.birthPlace"></el-input>
                  </el-form-item>
                  <el-form-item label="与本人关系" size="small">
                    <el-input v-model="teamRow.relation"></el-input>
                  </el-form-item>
                </el-col>
                <el-col style="width: 900px">
                  <el-form-item label="现住地址" size="small">
                    <el-input v-model="teamRow.currentAddress"></el-input>
                  </el-form-item>
                  <el-form-item label="户籍地址" size="small">
                    <el-input v-model="teamRow.residenceAddress"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-collapse-item>
            <el-collapse-item title="技术职称信息" name="3">
              <el-row>
                <el-col class="other">
                  <el-form-item label="职称" size="small">
                    <el-select v-model="teamRow.jobTitle" placeholder="请选择">
                      <el-option
                        v-for="item in global.jobTitleList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="执业注册" size="small">
                    <el-input v-model="teamRow.professionalRegistered"></el-input>
                  </el-form-item>
                  <el-form-item label="印章号" size="small">
                    <el-input v-model="teamRow.stampNum"></el-input>
                  </el-form-item>
                </el-col>
                <el-col class="other">
                  <el-form-item label="职称专业" size="small">
                    <el-input v-model="teamRow.jobTitleProfession"></el-input>
                  </el-form-item>
                  <el-form-item label="执业专业" size="small">
                    <el-input v-model="teamRow.occupation"></el-input>
                  </el-form-item>
                  <el-form-item label="印章有效期" size="small">
                    <el-date-picker
                      v-model="teamRow.stampTime"
                      type="date"
                      value-format="timestamp"
                      placeholder="选择日期"
                      style="width: 190px">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col class="other">
                  <el-form-item label="证书取得时间" size="small">
                    <el-date-picker
                      v-model="teamRow.jobTitleTime"
                      type="date"
                      value-format="timestamp"
                      placeholder="选择日期"
                      style="width: 190px">
                    </el-date-picker>
                  </el-form-item>
                  <el-form-item label="执业证书编号" size="small">
                    <el-input v-model="teamRow.professionalCertificate"></el-input>
                  </el-form-item>


                </el-col>
              </el-row>
            </el-collapse-item>
            <el-collapse-item title="社保公积金信息" name="4">
              <el-row>
                <el-form-item label="社保情况" size="small">
                </el-form-item>
                <el-col class="other">
                  <el-form-item prop="socialSecurity.insuredStatus" label="参保状态" size="small">
                    <el-select v-model="teamRow.socialSecurity.insuredStatus" placeholder="请选择" disabled>
                      <el-option
                        v-for="item in global.insuredStatusList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="缴费基数" size="small">
                    <el-input type="number" v-model.number="teamRow.socialSecurity.insuredBase" disabled></el-input>
                  </el-form-item>
                  <!--<el-form-item label="个人缴纳系数" size="small" >-->
                  <!--<el-input type="number" v-model.number="teamRow.socialSecurity.personalBase" disabled></el-input>-->
                  <!--</el-form-item>-->
                </el-col>
                <el-col class="other">
                  <el-form-item label="参保单位" size="small">
                    <el-select v-model="teamRow.socialSecurity.insuredUnit" placeholder="请选择" disabled>
                      <el-option
                        v-for="item in global.insuredUnitList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>

                </el-col>
                <el-col class="other">
                  <el-form-item label="参保时间" size="small">
                    <el-date-picker
                      v-model="teamRow.socialSecurity.startTime"
                      type="date"
                      value-format="timestamp"
                      placeholder="选择日期"
                      style="width: 190px"
                      disabled
                    >
                    </el-date-picker>
                  </el-form-item>
                  <!--<el-form-item label="公司缴纳系数" size="small" >-->
                  <!--<el-input type="number" v-model.number="teamRow.socialSecurity.companyBase" disabled></el-input>-->
                  <!--</el-form-item>-->
                </el-col>
              </el-row>
              <el-row>
                <el-form-item label="公积金情况" size="small">
                </el-form-item>
                <el-col class="other">
                  <el-form-item prop="accumulationFund.insuredStatus" label="参缴状态" size="small">
                    <el-select v-model="teamRow.accumulationFund.insuredStatus" placeholder="请选择" disabled>
                      <el-option
                        v-for="item in global.insuredStatus1List"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="缴费基数" size="small">
                    <el-input type="number" v-model.number="teamRow.accumulationFund.insuredBase" disabled></el-input>
                  </el-form-item>
                  <!--<el-form-item label="个人缴纳系数" size="small" >-->
                  <!--<el-input type="number" v-model.number="teamRow.accumulationFund.personalBase" disabled></el-input>-->
                  <!--</el-form-item>-->
                </el-col>
                <el-col class="other">
                  <el-form-item label="参缴单位" size="small">
                    <el-select v-model="teamRow.accumulationFund.insuredUnit" placeholder="请选择" disabled>
                      <el-option
                        v-for="item in global.insuredUnit1List"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col class="other">
                  <el-form-item label="参缴时间" size="small">
                    <el-date-picker
                      v-model="teamRow.accumulationFund.startTime"
                      type="date"
                      value-format="timestamp"
                      placeholder="选择日期"
                      style="width: 190px"
                      disabled
                    >
                    </el-date-picker>
                  </el-form-item>
                  <!--<el-form-item label="公司缴纳系数" size="small" >-->
                  <!--<el-input type="number" v-model.number="teamRow.accumulationFund.companyBase" disabled></el-input>-->
                  <!--</el-form-item>-->
                </el-col>
              </el-row>
            </el-collapse-item>
            <el-collapse-item title="档案信息" name="5">
              <el-row>
                <el-col class="other">
                  <el-form-item label="档案存放地" size="small">
                    <el-select v-model="teamRow.archivesAddress" placeholder="请选择">
                      <el-option
                        v-for="item in global.archivesAddressList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col class="other">
                  <el-form-item prop="contractStartTime" label="合同起始时间" size="small">
                    <el-date-picker
                      v-model="teamRow.contractStartTime"
                      type="date"
                      value-format="timestamp"
                      placeholder="选择日期"
                      style="width: 190px">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col class="other">
                  <el-form-item prop="contractExpired" label="合同终止时间" size="small">
                    <el-date-picker
                      v-model="teamRow.contractExpired"
                      type="date"
                      value-format="timestamp"
                      placeholder="选择日期"
                      style="width: 190px">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-collapse-item>
            <el-collapse-item title="离职信息" name="6">
              <el-row>
                <el-col class="other">
                  <el-form-item label="离职日期" size="small">
                    <el-date-picker
                      v-model="teamRow.leaveDate"
                      type="date"
                      value-format="timestamp"
                      placeholder="选择日期"
                      style="width: 190px"
                      disabled
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-collapse-item>
          </el-collapse>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="warning" size="small"  @click="submitForm('teamRow')" v-no-more-click>确定</el-button>
          <el-button size="small" @click="outerVisible = false">取消</el-button>
        </div>
      </el-dialog>
    </div>
    <my-table
      :data="tableData"
      :col-configs="colConfigs"
      v-loading="listLoading"
      :page-num="pageNum"
      :page-size="pageSize"
    >
      <el-table-column
        slot="opt"
        fixed="right"
        label="操作"
        width="120"
        v-if="roleType!==6"
      >
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="editTeam(scope.row.employeeId)"
            type="text"
            size="small">
            修改
          </el-button>
          <el-popover
            placement="top"
            width="160"
            :ref="`popover-${scope.$index}`"
          >
            <p>确定删除这条数据吗?</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[`popover-${scope.$index}`].doClose()">取消</el-button>
              <el-button type="primary" size="mini" @click.native.prevent="deleteRow(scope)">确定</el-button>
            </div>
            <el-button type="text" size="small" slot="reference" v-popover:popover-${scope.$index}>删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </my-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
  import {
    addEmployee,
    changeEmployee,
    delEmployee,
    findInfoById,
    getListEmployee,
    selectTeam,
    downloadRoster,
    exportEmployeeExcel
  } from '@/api/roster'
  import myTable from '@/components/myTable'
  import global from '@/components/global'

  import { Message } from 'element-ui'
  import { AreaSelect } from 'vue-area-linkage'
  import { pca } from 'area-data'
  import { formatDate } from '@/utils/index'
  import { isvalidPhone } from '@/utils/validate'

  // const teamName = function(row, column) {
  //   if (row.affiliatedPerson) {
  //     return row.affiliatedPerson
  //   } else {
  //     return row.teamName
  //   }
  // }

  const tertiarySector = function(row, column) {
    if (row.tertiarySector) {
      return row.tertiarySector
    } else {
      if (row[column.property]) {
        let obj = {}
        obj = global[`${column.property}List`].find((item) => {
          return item.value === row[column.property] // 筛选出匹配数据
        })
        return obj.label
      }
    }
  }

  const formatter = function(row, column) {
    if (row[column.property]) {
      let obj = {}
      obj = global[`${column.property}List`].find((item) => {
        return item.value === row[column.property] // 筛选出匹配数据
      })
      return obj.label
    }
  }

  const time = {
    props: ['colConfig'],
    filters: {
      formatDate(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyy-MM-dd')
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        {{ scope.row[colConfig.prop] | formatDate }}
      </span>
  </el-table-column>
  `
  }

  const configs = {
    props: ['colConfig'],
    filters: {
      formatMonth(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyyMM')
      },
      formatDate(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyyMMdd')
      },
      formatTime(time) {
        console.log(time)
        var date = new Date(time)
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      },
      formatter(row, prop) {
        if (row[prop]) {
          let obj = {}
          obj = global[`${prop}List`].find((item) => {
            return item.value === row[prop] // 筛选出匹配数据
          })
          return obj.label
        }
      }
    },
    template: `
  <el-table-column :label="colConfig.label">
            <el-table-column  v-for="(item, index) in colConfig.children"  :label="item.label" :width="item.width">
                <span slot-scope="scope" >
                    <span v-if="item.component==='month'"> {{ scope.row[item.prop] | formatMonth }}</span>
                    <span v-else-if="item.component==='time'"> {{ scope.row[item.prop] | formatDate }}</span>
                    <span v-else-if="item.component==='formatter'"> {{ scope.row,item.prop | formatter }}</span>
                    <span v-else >{{scope.row[item.prop]}}</span>
                </span>
            </el-table-column>
  </el-table-column>
  `
  }

  const sex = function(row, column) {
    return row.sex ? '男' : '女'
  }

  const employeeAge = function(row, column) {
    if (row.birthday) {
      return Math.floor((new Date().getTime() - row.birthday) / 1000 / 60 / 60 / (24 * 30 * 12)) || 0
    }
  }

  const age = function(row, column) {
    if (row.hireDate) {
      return `${Math.floor((new Date().getTime() - row.hireDate) / 1000 / 60 / 60 / (24 * 30 * 12)) || 0}年${Math.floor((Math.floor((new Date().getTime() - row.hireDate) / 1000 / 60 / 60 % (24 * 30 * 12))) / (24 * 30)) || 0}月`
    }
  }

  const workYear = function(row, column) {
    if (row.graduationTime) {
      return `${Math.floor((new Date().getTime() - row.graduationTime) / 1000 / 60 / 60 / (24 * 30 * 12)) || 0}年${Math.floor((Math.floor((new Date().getTime() - row.graduationTime) / 1000 / 60 / 60 % (24 * 30 * 12))) / (24 * 30)) || 0}月`
    }
  }

  export default {
    components: {
      myTable,
      AreaSelect
    },
    data() {
      const validPhone = (rule, value, callback) => {
        if (!value) {
          callback(new Error('请输入联系电话'))
        } else if (!isvalidPhone(value)) {
          callback(new Error('请输入正确的11位手机号码'))
        } else {
          callback()
        }
      }
      const validPhone1 = (rule, value, callback) => {
        if (!value) {
          callback()
        } else if (!isvalidPhone(value)) {
          callback(new Error('请输入正确的11位手机号码'))
        } else {
          callback()
        }
      }
      return {
        colConfigs: [
          { prop: 'secondarySector', label: '部门', width: '100', fixed: true, formatter: tertiarySector },
          { prop: 'name', label: '姓名', width: '100', fixed: true },
          { prop: 'classification', label: '分类', width: '100', formatter: formatter },
          { prop: 'genre', label: '类型', width: '100', formatter: formatter },
          { prop: 'primarySector', label: '一级部门', width: '100', formatter: formatter },
          { prop: 'secondarySector', label: '二级部门', width: '100', formatter: formatter },
          { prop: 'tertiarySector', label: '三级部门', width: '100' },
          { prop: 'employeeCode', label: '员工编号', width: '150' },
          { prop: 'teamName', label: '所属团队', width: '100' },
          { prop: 'position', label: '职务', width: '80' },
          { prop: 'rank', label: '职级', width: '60', formatter: formatter },
          { prop: 'form', label: '用工形式', width: '100', formatter: formatter },
          { prop: 'sex', label: '性别', width: '60', formatter: sex },
          { prop: 'idNumber', label: '身份证', width: '150' },
          { prop: 'tel', label: '联系电话', width: '150' },
          { prop: 'birthday', label: '出生日期', width: '100', component: time },
          { prop: 'employeeAge', label: '年龄(岁)', width: '80', formatter: employeeAge },
          { prop: 'hireDate', label: '入职日期', width: '100', component: time },
          { prop: 'age', label: '司龄', width: '80', formatter: age },
          { prop: 'email', label: '邮箱', width: '150' },
          { prop: 'education', label: '文化程度', width: '80', formatter: formatter },
          { prop: 'graduationSchool', label: '毕业院校', width: '150' },
          { prop: 'professional', label: '专业', width: '100' },
          { prop: 'graduationTime', label: '毕业时间', width: '100', component: time },
          { prop: 'workYear', label: '工作年限', width: '80', formatter: workYear },
          { prop: 'marriage', label: '婚姻状况', width: '80', formatter: formatter },
          { prop: 'political', label: '政治面貌', width: '80', formatter: formatter },
          { prop: 'birthPlace', label: '籍贯', width: '80' },
          { prop: 'residenceAddress', label: '户籍地址', width: '150' },
          { prop: 'currentAddress', label: '现住地址', width: '150' },
          {
            label: '紧急联络方式', children: [
              { prop: 'urgentPeople', label: '联络人', width: '80' },
              { prop: 'homePhone', label: '联络电话', width: '100' },
              { prop: 'relation', label: '与本人关系', width: '100' }
            ], component: configs
          },
          {
            label: '职称', children: [
              { prop: 'jobTitle', label: '职称', width: '100', component: 'formatter' },
              { prop: 'jobTitleProfession', label: '专业', width: '100' },
              { prop: 'jobTitleTime', label: '取得时间', width: '100', component: 'time' }
            ], component: configs
          },
          {
            label: '执业注册', children: [
              { prop: 'professionalRegistered', label: '注册', width: '150' },
              { prop: 'occupation', label: '专业', width: '150' },
              { prop: 'professionalCertificate', label: '证书编号', width: '150' },
              { prop: 'stampNum', label: '印章号', width: '150' },
              { prop: 'stampTime', label: '印章有效期', width: '100', component: 'time' }
            ], component: configs
          },
          {
            label: '社保', children: [
              { prop: 'insuredStatus', label: '参保状态', width: '80', component: 'formatter' },
              { prop: 'insuredUnit', label: '参保单位', width: '100', component: 'formatter' },
              { prop: 'startTime', label: '参保时间', width: '100', component: 'month' },
              { prop: 'insuredBase', label: '缴费基数(元)', width: '100' }
            ], component: configs
          },
          {
            label: '公积金', children: [
              { prop: 'insuredStatus1', label: '参保状态', width: '80', component: 'formatter' },
              { prop: 'insuredUnit1', label: '参保单位', width: '100', component: 'formatter' },
              { prop: 'startTime1', label: '参保时间', width: '100', component: 'month' },
              { prop: 'insuredBase1', label: '缴费基数(元)', width: '100' }
            ], component: configs
          },
          { prop: 'archivesAddress', label: '档案存放地', width: '150', formatter: formatter },
          {
            label: '劳动合同', children: [
              { prop: 'contractStartTime', label: '起止时间', width: '100', component: 'time' },
              { prop: 'contractExpired', label: '到期时间', width: '100', component: 'time' }
            ], component: configs
          },
          { prop: 'leaveDate', label: '离职日期', width: '100', component: time },
          { slot: 'opt' }
        ],
        searchForm: {
          isDimission: 1
        },
        searchFormList: {
          isDimission: 1
        },
        teams: [],
        roles: [],
        typeNames: [],
        listLoading: true,
        dialogTitle: '新增员工',
        dialogType: 0,
        teamRow: {
          socialSecurity: {},
          accumulationFund: {}
        },
        teamRowClear: {},
        socialSecurity: {},
        accumulationFund: {},
        tableData: [],
        pageNum: 1,
        pageSize: 10,
        total: 1,
        outerVisible: false,
        pca: pca,
        rules: {
          teamName: [
            { required: true, message: '请输入所属团队', trigger: 'change' }
          ],
          name: [
            { required: true, message: '请输入员工姓名', trigger: 'change' }
          ],
          sex: [
            { required: true, message: '请选择性别', trigger: 'change' }
          ],
          // idNumber: [
          //   { required: true, message: '请输入身份证', trigger: 'change' }
          // ],
          // tel: [
          //   { required: true, trigger: 'change', validator: validPhone }
          // ],
          hireDate: [
            { required: true, message: '请选择入职时间', trigger: 'change' }
          ],
          // contractStartTime: [
          //   { required: true, message: '请选择合同起始时间', trigger: 'change' }
          // ],
          // contractExpired: [
          //   { required: true, message: '请选择合同结束时间', trigger: 'change' }
          // ],
          age: [
            { required: true, message: '请输入司龄', trigger: 'change' }
          ],
          homePhone: [
            { required: false, trigger: 'change', validator: validPhone1 }
          ]
        },
        visible: false,
        isDisabled: false,
        photoPath: {},
        entryForm: {},
        teamRowCollapse: '1',
        exportUrl: '' // 导出参数
      }
    },
    created() {
      this.teamRowClear = JSON.parse(JSON.stringify(this.teamRow))
      this.fetchData()
    },
    computed: {
      global() {
        return global
      },
      roleType() {
        return this.$store.state.user.roleType
      }
    },
    methods: {
      fetchData() {
        this.searchFormList.pageNum = this.pageNum
        this.searchFormList.pageSize = this.pageSize
        this.listLoading = true
        getListEmployee(this.searchFormList).then(response => {
          this.tableData = response.responseBody.list
          this.total = response.responseBody.total
          console.log(this.tableData)
          this.listLoading = false
        })
      },
      search() {
        this.pageNum = 1
        this.searchFormList = JSON.parse(JSON.stringify(this.searchForm))
        this.fetchData()
      },
      addTeam() {
        if (this.$refs['teamRow']) {
          this.$refs['teamRow'].resetFields()
        }
        this.outerVisible = true
        this.isDisabled = false
        this.dialogTitle = '新增员工'
        this.teamRow = JSON.parse(JSON.stringify(this.teamRowClear))
        this.dialogType = 1
        if (this.$refs.infoFile) {
          this.$refs.infoFile.value = ''
        }
      },
      editTeam(employeeId) {
        if (this.$refs['teamRow']) {
          this.$refs['teamRow'].resetFields()
        }
        this.outerVisible = true
        this.isDisabled = true
        this.dialogTitle = '修改员工'
        this.teamRow = JSON.parse(JSON.stringify(this.teamRowClear))
        this.dialogType = 0
        if (this.$refs.infoFile) {
          this.$refs.infoFile.value = ''
        }
        const params = {
          employeeId: employeeId
        }
        findInfoById(params).then(response => {
          const data = response.responseBody
          this.teamRow = Object.assign({}, this.teamRow, data)
          if (!this.teamRow.birthday) {
            delete this.teamRow.birthday
          }
          if (!this.teamRow.hireDate) {
            delete this.teamRow.hireDate
          }
          if (!this.teamRow.graduationTime) {
            delete this.teamRow.graduationTime
          }
        })
      },
      submitForm(formName) {
        const params = {
          classification: this.teamRow.classification || '',
          genre: this.teamRow.genre || '',
          primarySector: this.teamRow.primarySector || '',
          secondarySector: this.teamRow.secondarySector || '',
          employeeCode: this.teamRow.employeeCode || '',
          tertiarySector: this.teamRow.tertiarySector,
          teamId: this.teamRow.teamId,
          teamName: this.teamRow.teamName,
          affiliatedPerson: this.teamRow.affiliatedPerson || '',
          position: this.teamRow.position || '',
          rank: this.teamRow.rank || '',
          name: this.teamRow.name,
          form: this.teamRow.form || '',
          sex: this.teamRow.sex,
          idNumber: this.teamRow.idNumber,
          tel: this.teamRow.tel,
          birthday: this.teamRow.birthday,
          employeeAge: Math.floor((new Date().getTime() - this.teamRow.birthday) / 1000 / 60 / 60 / (24 * 30 * 12)) || 0,
          hireDate: this.teamRow.hireDate,
          age: `${Math.floor((new Date().getTime() - this.teamRow.hireDate) / 1000 / 60 / 60 / (24 * 30 * 12)) || 0}年${Math.floor((Math.floor((new Date().getTime() - this.teamRow.hireDate) / 1000 / 60 / 60 % (24 * 30 * 12))) / (24 * 30)) || 0}月`,
          email: this.teamRow.email || '',
          education: this.teamRow.education || '',
          graduationSchool: this.teamRow.graduationSchool || '',
          professional: this.teamRow.professional || '',
          graduationTime: this.teamRow.graduationTime,
          workYear: `${Math.floor((new Date().getTime() - this.teamRow.graduationTime) / 1000 / 60 / 60 / (24 * 30 * 12)) || 0}年${Math.floor((Math.floor((new Date().getTime() - this.teamRow.graduationTime) / 1000 / 60 / 60 % (24 * 30 * 12))) / (24 * 30)) || 0}月`,
          marriage: this.teamRow.marriage || '',
          political: this.teamRow.political || '',
          birthPlace: this.teamRow.birthPlace || '',
          urgentPeople: this.teamRow.urgentPeople || '',
          homePhone: this.teamRow.homePhone || '',
          relation: this.teamRow.relation || '',
          currentAddress: this.teamRow.currentAddress || '',
          residenceAddress: this.teamRow.residenceAddress || '',
          jobTitle: this.teamRow.jobTitle || '',
          jobTitleProfession: this.teamRow.jobTitleProfession || '',
          jobTitleTime: this.teamRow.jobTitleTime,
          professionalRegistered: this.teamRow.professionalRegistered || '',
          occupation: this.teamRow.occupation || '',
          professionalCertificate: this.teamRow.professionalCertificate || '',
          stampNum: this.teamRow.stampNum || '',
          stampTime: this.teamRow.stampTime,
          archivesAddress: this.teamRow.archivesAddress || '',
          contractStartTime: this.teamRow.contractStartTime,
          contractExpired: this.teamRow.contractExpired
        }
        if (!this.dialogType) {
          params.employeeId = this.teamRow.employeeId
        }
        if (this.teamRow.teamId) {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              if (this.dialogType) {
                addEmployee(params).then(response => {
                  this.outerVisible = false
                  this.fetchData()
                })
              } else {
                changeEmployee(params).then(response => {
                  this.outerVisible = false
                  this.fetchData()
                })
              }
            } else {
              console.log('error submit!!')
              return false
            }
          })
        } else {
          this.$message({
            message: '该团队不存在',
            type: 'warning'
          })
        }
      },
      deleteRow(scope) {
        this.$refs[`popover-${scope.$index}`].doClose()
        const params = {
          employeeId: scope.row.employeeId,
          isDel: 1
        }
        delEmployee(params).then(response => {
          this.fetchData()
        })
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.pageNum = val
        this.fetchData()
      },
      querySearchTertiarySector(queryString, callback) {
        // queryString 为在框中输入的值
        // callback 回调函数,将处理好的数据推回
        if (queryString) {
          const params = {
            teamName: queryString
          }
          selectTeam(params).then(response => {
            for (const i of response.responseBody) {
              i.value = i.teamName
            }
            let nameList = response.responseBody
            if (nameList.length === 0) {
              nameList = [{ value: '暂无数据' }]
            }
            callback(nameList)
          })
        } else {
          callback([])
        }
      },
      querySearchTeam(queryString, callback) {
        // queryString 为在框中输入的值
        // callback 回调函数,将处理好的数据推回
        delete this.teamRow.teamId
        if (queryString) {
          const params = {
            teamName: queryString
          }
          selectTeam(params).then(response => {
            for (const i of response.responseBody) {
              i.value = i.teamName
            }
            let nameList = response.responseBody
            if (nameList.length === 0) {
              nameList = [{ value: '暂无数据' }]
            }
            callback(nameList)
          })
        } else {
          callback([])
        }
      },
      handleSelectTeam(item) {
        this.$set(this.teamRow, 'teamId', item.teamId)
        this.$set(this.teamRow, 'teamName', item.teamName)
      },
      downloadFile() {
        this.$refs.file.click()
      },
      fileChanged() {
        const excel = this.$refs.file.value
        const params = new FormData()
        console.log(this.$refs.file.value)
        var reg = /^.*\.(?:xls|xlsx)$/i
        if (!reg.test(excel)) {
          Message({
            message: '请上传excel格式的文件!',
            type: 'error',
            duration: 5 * 1000
          })
          return
        } else {
          params.append('file', this.$refs.file.files[0])
          downloadRoster(params).then(response => {
            this.fetchData()
          })
          if (this.$refs.file) {
            this.$refs.file.value = ''
          }
        }
      }
    },
    mounted() {
    },
    watch: {
      'searchForm': {
        handler(newValue, oldValue) {
          let exportUrl = ''
          Object.keys(this.searchForm).map((key) => {
            exportUrl += key + '=' + this.searchForm[key] + '&'
          })
          this.exportUrl = exportUrl
        },
        immediate: true,
        deep: true // 深度监听
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .app-container {
    .el-pagination {
      margin-top: 20px;
    }
    .table-btn {
      margin-bottom: 10px;
      & > button {
        margin: 0 20px;
      }
      .el-dialog {
        textarea {
          margin-top: 10px;
        }
        .el-checkbox {
          margin-right: 20px;
        }
        .el-checkbox + .el-checkbox {
          margin-left: 0;
        }
      }
      .file {
        display: none;
      }
    }
    .active-pic {
      font-size: 0.6rem;
      color: #9b9b9b;
      padding: 0 1rem 0 1.5rem;
      margin-top: 1rem;
    }
    .fileHidden {
      display: none;
    }
    .imgSrc {
      position: relative;
      width: 215px;
      height: 300px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 6px;
      }
      i {
        position: absolute;
        top: 10px;
        right: 10px;
        cursor: pointer;
      }
    }
    .imgPlus {
      width: 215px;
      height: 300px;
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 30px;
      &:hover {
        border-color: #409EFF;
      }
    }
    .entryFormSrc {
      position: relative;
      width: 100%;
      min-height: 300px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 6px;
      }
      i {
        position: absolute;
        top: 10px;
        right: 10px;
        cursor: pointer;
      }
    }
    .entryFormPlus {
      width: 100%;
      height: 300px;
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 30px;
      &:hover {
        border-color: #409EFF;
      }
    }
    .other {
      width: 300px;
    }
    .ageOther {
      width: 350px;
    }
    .datePicker {
      display: flex;
      flex-direction: row;
    }
  }

</style>


<style rel="stylesheet/scss" lang="scss">
  .el-input__icon {
    line-height: 100%;
  }

  .el-form-item__content {
    line-height: 33px;
  }

  .area-select .area-selected-trigger {
    padding: 0 10px;
  }

  /*.el-table__body tr.hover-row>td {
  background-color: #0000ff !important;
  }

  .el-table__body tr.current-row>td {
  background-color: #0000ff !important;
  }*/
</style>
